<?php

declare (strict_types=1);

namespace App\Model;

/**
 * @property int $id
 * @property string $game_hash
 * @property string $connection_code
 * @property string $kong_code
 * @property string $version
 * @property int $status
 */
class QmGameVersion extends Model {
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'qm_game_version';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['id' => 'integer', 'status' => 'integer'];

    /**
     * 获取链接标识
     * @param $game_hash
     * @param $version
     * @return \Hyperf\Utils\HigherOrderTapProxy|mixed|string|null
     */
    public function getCode($game_hash, $version) {
        $gameInfo = self::query()->where('game_hash', $game_hash)
            ->where('version', $version)->first();
        if ($gameInfo && $gameInfo['status'] != 4) {
            return $gameInfo['connection_code'];
        } else {
            return '';
        }
    }
}